import scrapy
from gamerank.items import GamerankItem

class Gamerank(scrapy.Spider):
    name = 'game'
    allowed_domains=['9game.cn']
    start_url = []
    for i in range(1,5):
        url = "http://www.9game.cn/xyrb"
        url = url+str(i)+'_0/'
        start_url.append(url)
    start_url

    def parse(self, response):
        item = GamerankItem()
        games = response.xpath('//tr')

        for each_ga in games:
            if len(each_ga.xpath('./td')) ==0:
                continue

                item['rank']=each_ga.xpath('/td/sapn[@class="n "]/text()').extract()[0]
                item['game'] = each_ga.xpath('/td[@class="name"]/a/text()').extract()[0]
                item['type'] = each_ga.xpath('/td[@class="type"]/text()').extract()[0]
                item['status'] = each_ga.xpath('/td[@class="staic"]/span/text() | ./td[@class="time time1"]/div[@class="t"]/text()').extract()[0]
                item['hot'] = each_ga.xpath('/td[@class="hottr hot"]/span/text()').extract()[0]
                yield item